/* rqaval1.p - Approver Maintenance Key Validation Program                  */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.             */
/* $Revision: 1.3.1.2 $                                                             */
/*V8:ConvertMode=NoConvert                                                  */
/* REVISION 8.5       LAST MODIFIED: 04/15/97  BY: *J1Q2* Patrick Rowan     */
/* REVISION 8.6       LAST MODIFIED: 05/20/98  BY: *K1Q4* Alfred Tan        */
/* REVISION 8.5       LAST MODIFIED: 11/01/98  BY: *J32W* Patrick Rowan     */
/* REVISION 9.1       LAST MODIFIED: 08/12/00  BY: *N0KP* myb               */
/* Old ECO marker removed, but no ECO header exists *F0PN*                  */
/* $Revision: 1.3.1.2 $       BY: Manisha Sawant       DATE: 10/21/01  ECO: *N14P*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: Edits/Validates approver maintenance key fields
              Supports the multi-line Purchase Requisition Module of MFG/PRO.

 Notes:
 1) in_apr_type is used to indicate approver type and determines what key
fields require edits/validation.
============================================================================
!*/
{mfdeclre.i " "}

/* CONSTANTS */
{rqconst.i}

/* VALIDATE KEY FIELDS */

define input parameter in_apr      like rqa_apr no-undo.
define input parameter in_apr_type like rqa_type no-undo.
define input parameter in_entity   like rqa_entity no-undo.
define input parameter in_category like rqa_category no-undo.
define input parameter in_job      like rqa_job no-undo.
define input parameter in_site     like rqa_site no-undo.
define input parameter in_prod_line
   like rqa_prod_line no-undo.

define output parameter out_valid_apr
   like mfc_logical no-undo.
define output parameter out_valid_entity
   like mfc_logical no-undo.
define output parameter out_valid_category
   like mfc_logical no-undo.
define output parameter out_valid_job
   like mfc_logical no-undo.
define output parameter out_valid_site
   like mfc_logical no-undo.
define output parameter out_valid_prod_line
   like mfc_logical no-undo.

/* INITIALIZE */
assign
   out_valid_apr       = no
   out_valid_entity    = no
   out_valid_category  = no
   out_valid_job       = no
   out_valid_site      = no
   out_valid_prod_line = no.

/* APPROVER ID */
/* REQUIRED FOR ALL APPROVERS */
if can-find(usr_mstr
   where usr_mstr.usr_userid = in_apr)
then
   out_valid_apr = yes.

/* ENTITY */
/* REQUIRED FOR HORIZONTAL, VERTICAL, JOB APPROVERS */
/* MAKE SURE AN ENTITY HAS BEEN ENTERED. A ""       */
/* MAY BE A VALID ENTITY, BUT NOT HERE.             */
/* ENTITIES ARE VALID FROM 2 SOURCES:               */
/* 1) SYSTEM/ACCOUNTS CONTROL FILE, OR              */
/* 2) ENTITY MASTER.                                */
/* OPTIONAL FOR HORIZONTAL, VERTICAL, JOB APPROVERS */
if in_apr_type = horizontal or
   in_apr_type = vertical or
   in_apr_type = JOB
then do:
   if in_entity = ""
   then
      out_valid_entity = yes.
   else
      if in_entity = glentity or
         can-find(en_mstr
            where en_mstr.en_entity = in_entity)
      then
         out_valid_entity = yes.

end.  /* if in_apr_type */

/* CATEGORY */
/* REQUIRED FOR HORIZONTAL APPROVERS */
if in_apr_type = horizontal or
   in_apr_type = vertical or
   in_apr_type = JOB
then do:
   if can-find(rqc_mstr
      where rqc_mstr.rqc_category = in_category)
   then
      out_valid_category = yes.
   else
      out_valid_category = no.

end.  /* if in_apr_type */

/* JOB */
/* REQUIRED FOR JOB APPROVERS */
/* VALID JOBS ARE ACTIVE; WITH AN */
/* END EFFECTIVITY LATER THAN TODAY OR NO END EFFECTIVITY */
if in_apr_type = JOB
then do:
   if can-find(rqj_mstr
      where rqj_mstr.rqj_job = in_job
      and (rqj_end > today or rqj_end = ?))
   then
      out_valid_job = yes.

end.  /* if in_apr_type */

/* SITE */
/* REQUIRED FOR DIRECT APPROVERS (PRODUCT LINE) */
if in_apr_type = DIRECT
then do:
   if can-find(si_mstr
      where si_mstr.si_site = in_site)
   then
      out_valid_site = yes.

end.  /* if in_apr_type */

/* PRODUCT LINE */
/* REQUIRED FOR DIRECT APPROVERS (PRODUCT LINE) */
if in_apr_type = DIRECT
then do:
   if can-find(pl_mstr
      where pl_mstr.pl_prod_line = in_prod_line)
   then
      out_valid_prod_line = yes.

end.  /* if in_apr_type */

/* START DATE */
/* OPTIONAL FOR ALL APPROVERS */
/* NO VALIDATION */
